package cn.zhage.aimin.gateway1.auth;

import org.springframework.util.AntPathMatcher;

import java.util.LinkedHashMap;
import java.util.Map;

/*
 *
 * @author 渣哥
 */
public class StrategyFactory {

    private static final AntPathMatcher pathMatcher = new AntPathMatcher();


    private static final Map<String, LoginCheckStrategy> strategyMap = new LinkedHashMap<>();

    static {
        strategyMap.put("aimin-auth/public/**", new PublicStrategy());
        strategyMap.put("aimin-auth/test/adminLoginCheck", new AminAuthStrategy());
        strategyMap.put("aimin-auth/test/userLoginCheck", new UserAuthStrategy());
    }


    public static LoginCheckStrategy getStrategy(String requestUri){
        for (Map.Entry<String, LoginCheckStrategy> entry : strategyMap.entrySet()) {
            if (pathMatcher.match(entry.getKey(), requestUri)) {
                return entry.getValue();
            }
        }
        return new PublicStrategy(); // 默认策略
    }
}
